import 'package:flutter/material.dart';
import 'package:sz/tools/tools.dart';

class SzTab extends StatelessWidget {
  /// 标签页 (外层需要包裹大小容器)
  ///  values  选项数组
  ///  current 当前选中的tab索引值，从0计数
  /// clickItem 组件触发点击事件时触发	e={currentIndex}
  /// scrollDirection 方向
  /// itemMargin 每项边距
  /// bottomBorder 选中是否显示下边线
  const SzTab({
    Key? key,
    required this.values,
    required this.current,
    this.clickItem,
    this.activeColor = SzColor.primary,
    this.scrollDirection = Axis.horizontal,
    this.itemMargins,
    this.bottomBorder = true,
  }) : super(key: key);

  final List<String> values;
  final int current;
  final Function? clickItem;
  final Color? activeColor;
  final Axis? scrollDirection;
  final EdgeInsets? itemMargins;
  final bool? bottomBorder;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      scrollDirection: scrollDirection!,
      itemCount: values.length,
      itemBuilder: (BuildContext context, int index) {
        return GestureDetector(
          onTap: () {
            clickItem!(index);
          },
          child: Container(
            padding: itemMargins ?? EdgeInsets.symmetric(horizontal: rpx(30)),
            // decoration: BoxDecoration(color: Colors.red),
            child: Container(
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: Border(
                  bottom: index == current && bottomBorder!
                      ? BorderSide(
                          width: rpx(4),
                          color: activeColor!,
                        )
                      : BorderSide.none,
                ),
              ),
              child: Text(
                values[index],
                style: index == current
                    ? TextStyle(
                        fontWeight: FontWeight.bold,
                        color: activeColor,
                      )
                    : null,
              ),
            ),
          ),
        );
      },
    );
  }
}
